﻿--region Drop Existing Procedures

IF OBJECT_ID(N'[dbo].[spFlashCardIns]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardIns]

IF OBJECT_ID(N'[dbo].[spFlashCardUpd]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardUpd]

IF OBJECT_ID(N'[dbo].[spFlashCardInsUpd]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardInsUpd]

IF OBJECT_ID(N'[dbo].[spFlashCardDel]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDel]

IF OBJECT_ID(N'[dbo].[spFlashCardDelDyn]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDelDyn]

IF OBJECT_ID(N'[dbo].[spFlashCardSel]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSel]

IF OBJECT_ID(N'[dbo].[spFlashCardSelDyn]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelDyn]

IF OBJECT_ID(N'[dbo].[spFlashCardSelAll]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelAll]

IF OBJECT_ID(N'[dbo].[spFlashCardSelPgd]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelPgd]

IF OBJECT_ID(N'[dbo].[spFlashCardSelBySuggestedActionID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelBySuggestedActionID]

IF OBJECT_ID(N'[dbo].[spFlashCardSelByExplanationID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelByExplanationID]

IF OBJECT_ID(N'[dbo].[spFlashCardSelByDealersUpCardAndPlayersHand]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelByDealersUpCardAndPlayersHand]

IF OBJECT_ID(N'[dbo].[spFlashCardSelByFlashCardID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardSelByFlashCardID]

IF OBJECT_ID(N'[dbo].[spFlashCardDelBySuggestedActionID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDelBySuggestedActionID]

IF OBJECT_ID(N'[dbo].[spFlashCardDelByExplanationID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDelByExplanationID]

IF OBJECT_ID(N'[dbo].[spFlashCardDelByDealersUpCardAndPlayersHand]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDelByDealersUpCardAndPlayersHand]

IF OBJECT_ID(N'[dbo].[spFlashCardDelByFlashCardID]') IS NOT NULL
	DROP PROCEDURE [dbo].[spFlashCardDelByFlashCardID]

--endregion

GO

--region [dbo].[spFlashCardIns]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardIns]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------


CREATE PROCEDURE [dbo].[spFlashCardIns]
	@FlashCardID int,
	@ExplanationID int,
	@SuggestedActionID int,
	@DealersUpCard nvarchar(10),
	@PlayersHand nvarchar(200),
	@ToughHand bit
AS

SET NOCOUNT ON

INSERT INTO [dbo].[FlashCards] (
[ExplanationID],
[SuggestedActionID],
[DealersUpCard],
[PlayersHand],
[ToughHand]
) OUTPUT INSERTED.FlashCardID AS FlashCardID

VALUES (
@ExplanationID,
@SuggestedActionID,
@DealersUpCard,
@PlayersHand,
@ToughHand
)
;



--endregion

GO

--region [dbo].[spFlashCardUpd]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardUpd]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardUpd]
	@FlashCardID int,
	@ExplanationID int,
	@SuggestedActionID int,
	@DealersUpCard nvarchar(10),
	@PlayersHand nvarchar(200),
	@ToughHand bit
AS

SET NOCOUNT ON

UPDATE [dbo].[FlashCards] SET
	[ExplanationID] = @ExplanationID,
	[SuggestedActionID] = @SuggestedActionID,
	[DealersUpCard] = @DealersUpCard,
	[PlayersHand] = @PlayersHand,
	[ToughHand] = @ToughHand
WHERE
		[FlashCardID] = @FlashCardID
;
SELECT	@FlashCardID as FlashCardID;



--endregion

GO

--region [dbo].[spFlashCardInsUpd]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardInsUpd]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardInsUpd]
	@FlashCardID int,
	@ExplanationID int,
	@SuggestedActionID int,
	@DealersUpCard nvarchar(10),
	@PlayersHand nvarchar(200),
	@ToughHand bit
AS

SET NOCOUNT ON

IF EXISTS(SELECT [FlashCardID] FROM [dbo].[FlashCards] WHERE [FlashCardID] = @FlashCardID)
BEGIN
	UPDATE [dbo].[FlashCards] SET
		[ExplanationID] = @ExplanationID,
		[SuggestedActionID] = @SuggestedActionID,
		[DealersUpCard] = @DealersUpCard,
		[PlayersHand] = @PlayersHand,
		[ToughHand] = @ToughHand
	WHERE
		[FlashCardID] = @FlashCardID
	SELECT	@FlashCardID as FlashCardID;	
END
ELSE
BEGIN
	INSERT INTO [dbo].[FlashCards] (
		[ExplanationID],
		[SuggestedActionID],
		[DealersUpCard],
		[PlayersHand],
		[ToughHand]
	) 
	OUTPUT INSERTED.FlashCardID AS FlashCardID
	VALUES (
		@ExplanationID,
		@SuggestedActionID,
		@DealersUpCard,
		@PlayersHand,
		@ToughHand
	)
	;
END


--endregion

GO

--region [dbo].[spFlashCardDel]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDel]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardDel]
	@FlashCardID int
AS
SET NOCOUNT ON
DELETE FROM [dbo].[FlashCards]
WHERE
	[FlashCardID] = @FlashCardID
--endregion

GO


--region [dbo].[spFlashCardDelBySuggestedActionID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDelBySuggestedActionID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardDelBySuggestedActionID]
	@SuggestedActionID int
AS
SET NOCOUNT ON
DELETE FROM [dbo].[FlashCards]
WHERE
	[SuggestedActionID] = @SuggestedActionID

GO

--endregion

GO

--region [dbo].[spFlashCardDelByExplanationID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDelByExplanationID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardDelByExplanationID]
	@ExplanationID int
AS
SET NOCOUNT ON
DELETE FROM [dbo].[FlashCards]
WHERE
	[ExplanationID] = @ExplanationID

GO

--endregion

GO

--region [dbo].[spFlashCardDelByDealersUpCardAndPlayersHand]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDelByDealersUpCardAndPlayersHand]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardDelByDealersUpCardAndPlayersHand]
	@DealersUpCard nvarchar(10),
	@PlayersHand nvarchar(200)
AS

SET NOCOUNT ON

DELETE FROM [dbo].[FlashCards]
WHERE
	[DealersUpCard] = @DealersUpCard
	AND [PlayersHand] = @PlayersHand

--endregion

GO

--region [dbo].[spFlashCardDelByFlashCardID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDelByFlashCardID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardDelByFlashCardID]
	@FlashCardID int
AS

SET NOCOUNT ON

DELETE FROM [dbo].[FlashCards]
WHERE
	[FlashCardID] = @FlashCardID

--endregion

GO

--region [dbo].[spFlashCardDelDyn]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardDelDyn]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------


CREATE PROCEDURE [dbo].[spFlashCardDelDyn]
	@WhereCondition nvarchar(500)
AS

SET NOCOUNT ON

DECLARE @SQL nvarchar(3250)

SET @SQL = '
DELETE FROM
	[dbo].[FlashCards]
WHERE
	' + @WhereCondition

EXEC sp_executesql @SQL

--endregion

GO

--region [dbo].[spFlashCardSel]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSel]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSel]
	@FlashCardID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
WHERE
	[FlashCardID] = @FlashCardID

--endregion

GO

--region [dbo].[spFlashCardSelBySuggestedActionID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelBySuggestedActionID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelBySuggestedActionID]
	@SuggestedActionID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
WHERE
	[SuggestedActionID] = @SuggestedActionID

--endregion

GO

--region [dbo].[spFlashCardSelByExplanationID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelByExplanationID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelByExplanationID]
	@ExplanationID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
WHERE
	[ExplanationID] = @ExplanationID

--endregion

GO

--region [dbo].[spFlashCardSelByDealersUpCardAndPlayersHand]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelByDealersUpCardAndPlayersHand]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelByDealersUpCardAndPlayersHand]
	@DealersUpCard nvarchar(10),
	@PlayersHand nvarchar(200)
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
WHERE
	[DealersUpCard] = @DealersUpCard
	AND [PlayersHand] = @PlayersHand

--endregion

GO

--region [dbo].[spFlashCardSelByFlashCardID]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelByFlashCardID]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelByFlashCardID]
	@FlashCardID int
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
WHERE
	[FlashCardID] = @FlashCardID

--endregion

GO

--region [dbo].[spFlashCardSelDyn]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelDyn]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelDyn]
	@WhereCondition nvarchar(500),
	@OrderByExpression nvarchar(250) = NULL
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

DECLARE @SQL nvarchar(3250)

SET @SQL = '
SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
'
IF @WhereCondition IS NOT NULL AND LEN(@WhereCondition) > 0
BEGIN
	SET @SQL = @SQL + '
WHERE
	' + @WhereCondition
END

IF @OrderByExpression IS NOT NULL AND LEN(@OrderByExpression) > 0
BEGIN
	SET @SQL = @SQL + '
ORDER BY
	' + @OrderByExpression
END

EXEC sp_executesql @SQL

--endregion

GO

--region [dbo].[spFlashCardSelAll]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelAll]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------
CREATE PROCEDURE [dbo].[spFlashCardSelAll]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]
	


--endregion

GO

--region [dbo].[spFlashCardSelPgd]

------------------------------------------------------------------------------------------------------------------------
-- Generated By:   mbravo using CodeSmith 5.0.0.0
-- Template:       mbStoredProcedures.cst
-- Procedure Name: [dbo].[spFlashCardSelPgd]
-- Date Generated: Wednesday, September 22, 2010
------------------------------------------------------------------------------------------------------------------------

CREATE PROCEDURE [dbo].[spFlashCardSelPgd]
AS

SET NOCOUNT ON
SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

SELECT
	[FlashCardID],
	[ExplanationID],
	[SuggestedActionID],
	[DealersUpCard],
	[PlayersHand],
	[ToughHand]
FROM
	[dbo].[FlashCards]

--endregion

GO

